import React from 'react';
import { BrowserRouter as Router, Routes, Route, Navigate } from 'react-router-dom';
import { ThemeProvider } from '@/components/theme-provider';
import { AuthProvider } from '@/contexts/auth-context';
import { ProtectedRoute } from '@/components/auth/protected-route';
import LoginPage from '@/pages/login';
import DashboardPage from '@/pages/dashboard';
import ChatManagementPage from '@/pages/chat-management';
import ReleaseManagementPage from '@/pages/release-management';
import AnalyticsPage from '@/pages/analytics';
import UserManagementPage from '@/pages/user-management';
import SettingsPage from '@/pages/settings';
import MainLayout from '@/components/layout/main-layout';

function App() {
  return (
    <ThemeProvider defaultTheme="light" storageKey="vite-ui-theme">
      <AuthProvider>
        <Router>
          <Routes>
            {/* 登录页面 */}
            <Route path="/login" element={<LoginPage />} />
            
            {/* 受保护的主应用布局 */}
            <Route path="/" element={
              <ProtectedRoute>
                <MainLayout />
              </ProtectedRoute>
            }>
              <Route index element={<Navigate to="/dashboard" replace />} />
              <Route path="dashboard" element={<DashboardPage />} />
              <Route path="chat" element={<ChatManagementPage />} />
              <Route path="release" element={<ReleaseManagementPage />} />
              <Route path="analytics" element={<AnalyticsPage />} />
              <Route path="users" element={<UserManagementPage />} />
              <Route path="settings" element={<SettingsPage />} />
            </Route>
            
            {/* 默认重定向到登录页 */}
            <Route path="*" element={<Navigate to="/login" replace />} />
          </Routes>
        </Router>
      </AuthProvider>
    </ThemeProvider>
  );
}

export default App;
